package com.xidian.zhiancloud.controller.emergencyManagement;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xidian.zhiancloud.controller.base.BaseController;
import com.xidian.zhiancloud.dto.ResultDTO;
import com.xidian.zhiancloud.enums.GeneralResponseEnums;
import com.xidian.zhiancloud.model.DangerousChemicalStorage;
import com.xidian.zhiancloud.model.ReviewRecord;
import com.xidian.zhiancloud.qo.chemicalsManagement.DangerousChemicalStorageQO;
import com.xidian.zhiancloud.qo.emergencyManagement.ReviewRecordQO;
import com.xidian.zhiancloud.service.emergencyManagement.ReviewRecordService;
import com.xidian.zhiancloud.vo.chemicalsManagement.DangerousChemicalStorageVO;
import com.xidian.zhiancloud.vo.emergencyManagement.ReviewRecordVO;
import com.xidian.zhiancloud.vo.emergencyManagement.RevisionRecordVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * 应急管理 应急预案管理接口-评审订记录
 */
@RestController
@RequestMapping("/ReviewRecord")
public class ReviewRecordController extends BaseController {

    @Autowired
    private ReviewRecordService reviewRecordService;

    /**
     * 增加评审记录
     *
     * @param reviewRecord 评审记录对象
     * @return 返回是否添加成功
     */
    @PostMapping("/add")
    public ResultDTO<Boolean> add(ReviewRecord reviewRecord) {
        reviewRecord.setCreateTime(new Date(System.currentTimeMillis()));
        reviewRecord.setCreatorId(getSessionUserid());
        reviewRecord.setCompanyId(getSessionUserCompanyId());
        Boolean res = reviewRecordService.save(reviewRecord);
        return ResultDTO.successOf(res, GeneralResponseEnums.SUCCESS);
    }

    /**
     * 根据id删除评审记录
     *
     * @param ids ids数组
     * @return 返回是否删除成功
     */
    @PostMapping("/deleteByIds")
    public ResultDTO<Boolean> deleteByIds(Long[] ids) {

        return ResultDTO.successOf(reviewRecordService.removeByIds(Arrays.asList(ids)), GeneralResponseEnums.SUCCESS);
    }

    /**
     * 根据id修改评审记录对象
     *
     * @param reviewRecord 评审记录
     * @return 返回是否修改成功
     */
    @PostMapping("/patchById")
    public ResultDTO<Boolean> patchById(ReviewRecord reviewRecord) {
        reviewRecord.setCreateTime(null);
        reviewRecord.setCompanyId(null);
        reviewRecord.setCreatorId(null);
        return ResultDTO.successOf(reviewRecordService.updateById(reviewRecord), GeneralResponseEnums.SUCCESS);
    }

    /**
     * 根据id获取评审记录
     *
     * @param id 评审记录对象的id
     * @return 修订对象
     */
    @GetMapping("/getList")
    public ResultDTO<List<ReviewRecordVO>> getReviewRecord(@RequestParam("id") Long id) {
        return ResultDTO.successOf(reviewRecordService.getList(id), GeneralResponseEnums.SUCCESS);
    }

    /**
     * 列表查询
     *
     * @param reviewRecordQO 请求参数
     * @return 返回评审记录等列表
     */
    @GetMapping("/getListByQO")
    public ResultDTO<IPage<ReviewRecordVO>> getListByQueryObject(ReviewRecordQO reviewRecordQO) {
        if (reviewRecordQO.getCurrent() == null || reviewRecordQO.getSize() == null) {
            return ResultDTO.errorOf(GeneralResponseEnums.REQUEST_ERROR);
        }
        reviewRecordQO.setCompanyId(getSessionUserCompanyId());
        return ResultDTO.successOf(reviewRecordService.getListByQueryObject(reviewRecordQO), GeneralResponseEnums.SUCCESS);
    }

}